home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_087 / claz / claz.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  206 lines

  1. /*              CLAZ.c  v2.0                     */
  2. /*              by Steve Ludtke                  */
  3. /*              Created : 05/31/87               */
  4.  
  5. #include<stdio.h>
  6. #include<math.h>
  7. #include<exec/types.h>
  8.  
  9. /* define IFF structures */
  10. struct CMAP {
  11. UBYTE r,g,b;
  12. };
  13.  
  14. struct BMHD {
  15. UWORD w,h;
  16. WORD x,y;
  17. UBYTE npl;
  18. UBYTE masking,compression,pad1;
  19. UWORD tcolor;
  20. UBYTE xas,yas;
  21. WORD pWid,pHig;
  22. };
  23.  
  24. char *malloc();
  25.  
  26. main (argc,argv)
  27. int argc;
  28. char *argv[];
  29. {
  30. struct BMHD mhd;
  31. long *len1,*len2,cnt,rsz,m,h,i,j,k,d,lr,lb,lg,q1,q2,x1,x2,y1,y2,fl;
  32. int fl1,b;
  33. BYTE t;
  34. UBYTE cmap[100];
  35. char *raster,*rp,*fspin,*outfsp,hex[20],msc1[12],q,x,y,c,msc2[8],*misc;
  36. FILE *fin,*fout;
  37.  
  38. hex[0]='0'; hex[1]='1'; hex[2]='2'; hex[3]='3';
  39. hex[4]='4'; hex[5]='5'; hex[6]='6'; hex[7]='7';
  40. hex[8]='8'; hex[9]='9'; hex[10]='A'; hex[11]='B';
  41. hex[12]='C'; hex[13]='D'; hex[14]='E'; hex[15]='E';
  42. fl=0; x1=10; y1=10; x2=550; y2=480;
  43.  
  44. /* Get enough memory, figure out filespecs */
  45. raster=malloc(200000);
  46. misc=malloc(2000);
  47. if (raster==NULL) { printf("Not enough memory.\n"); exit(0); }
  48. if (argc<3) outfsp="out.ps";
  49. if (argc>2) outfsp=argv[2];
  50. if (argc>3) {
  51.     sscanf(argv[3],"%ld",&x1);
  52.     sscanf(argv[4],"%ld",&y1);
  53.     sscanf(argv[5],"%ld",&x2);
  54.     sscanf(argv[6],"%ld",&y2);
  55.     }
  56. if (argc==8 || argc==4) fl|=1;
  57.  
  58. printf("\n\n                CLAZ - IFF to POSTSCRIPT converter V2.0\n");
  59. printf("                           by Steve Ludtke\n");
  60. printf("                       N\251 - No Copyright 1987\n\n");
  61. printf("File in : ");
  62. if (argc>1) {
  63.     fspin=argv[1];
  64.     printf("%s\n",fspin);
  65.     }
  66. if (argc==1) {
  67.     fspin=malloc(80);
  68.     scanf("%s",fspin);
  69.     }
  70. fin=fopen(fspin,"r");
  71. if (fin==NULL) { printf("Sorry, can't open input file.\n"); exit(0); }
  72. if ((fread(msc1,12,1,fin))==0) { printf("Sorry, input file problem #1. \n"); exit (0); }
  73. len1=(long *)&msc1[4];
  74. printf("main : %d,%s\n",*len1,msc1);
  75. cnt=14;
  76.  
  77. /* *len1=# bytes in file according to IFF */
  78. /* msc2=the name of the current chunk */
  79. /* *len2=# bytes in current chunk */
  80. /* by the way, UNID is symply any chunk the program doesn't deal with */
  81.  
  82. /* Reads in the IFF file : */
  83.  
  84. while(cnt < *len1) {
  85. fl1=0;
  86. if ((fread(msc2,8,1,fin))==0) { printf("Sorry, bad input file. \n"); exit(0); }
  87. len2=(long *)&msc2[4];
  88.  
  89. if (strncmp(msc2,"CMAP",4)==0) {
  90.     if ((fread(cmap,*len2,1,fin))==0) { printf("Sorry, bad CMAP. \n"); exit(0); }
  91.     printf("CMAP\n");
  92.     fl1=1;
  93.     }
  94.  
  95. if ((strncmp(msc2,"BMHD",4))==0) {
  96.     if ((fread(&mhd,*len2,1,fin))==0) { printf("Sorry, bad BMHD. \n"); exit(0); }
  97.     printf("BMHD\n");
  98.     fl1=1;
  99.     }
  100.  
  101. if (strncmp(msc2,"BODY",4)==0) {
  102.     printf("BODY\n");
  103.     fl1=1;
  104.     m=0; rp=raster;
  105.     if (mhd.compression==1) {
  106.         while (m<=*len2) {
  107.             t=getc(fin); m++;
  108.             if (t>=0) { 
  109.                 t++;
  110.                 fread(rp,(long) t,1,fin);
  111.                 rp+=t;
  112.                 m+=t;
  113.                 }
  114.             if (t<0) {
  115.                 t=(-t)+1;
  116.                 c=getc(fin);
  117.                 m++;
  118.                 for (i=0; i<t; i++) {
  119.                         *rp=c; rp++; }
  120.                 }
  121.             }
  122.         }
  123.     if (mhd.compression==0) {
  124.         if ((fread(rp,*len2,1,fin))==0) { printf("Sorry, bad BODY. \n"); exit(0); }
  125.         printf("No Comression\n");
  126.         }
  127.     if (mhd.compression>1) { printf("Sorry, unknown compression type.\n");
  128.         exit(0); }
  129.     }
  130.  
  131. if (fl1==0) {
  132.     if (*len2>2000) { printf("Sorry, UNID too long.\n"); exit(0); }
  133.     if ((fread(misc,*len2,1,fin))==0) { printf("Sorry, UNID bad. \n"); exit(0); }
  134.     printf("UNID\n");
  135.     }
  136. cnt+=*len2;
  137. cnt+=8;
  138. }
  139.  
  140. fclose(fin);
  141. free(fspin);
  142.  
  143. if ((fout=fopen(outfsp,"a"))==NULL) { printf("Sorry, cannot open output file.\n"); exit(0); }
  144.  
  145. /* Standard POSTSCRIPT program, the only part following the data is */
  146. /* the showpage command. */
  147.  
  148. fprintf(fout,"[0 0 0 0 0 0] defaultmatrix setmatrix");
  149. fprintf(fout,"/picstr %d string def\r",mhd.w);
  150. fprintf(fout,"%ld %ld translate\r",x1,y1);
  151. fprintf(fout,"%ld %ld scale\r",x2,y2);
  152. fprintf(fout,"%d %d 4 [%d 0 0 -%d 0 %d]\r",mhd.w,mhd.h,mhd.w,mhd.h,mhd.h);
  153. fprintf(fout,"{currentfile picstr readhexstring pop} image\r");
  154.  
  155. /* calculate and output file */
  156.  
  157. lb=lr=lg=0;
  158. rsz=mhd.w*mhd.h/8;
  159. printf("rast size : %d     #planes : %d\n",rsz,mhd.npl);
  160. for (h=0; h<96; h++) cmap[h]=cmap[h]/16; 
  161. for (h=0; h<mhd.h; h++) {
  162. for (i=0; i<mhd.w/8; i++) {
  163.     for(k=7;k>=0;k--) {
  164.         b=0;
  165.         for(j=0; j<mhd.npl; j++) {
  166.             c=(raster[h*(mhd.w/8)*mhd.npl+i+((mhd.npl-j-1)*mhd.w/8)]);
  167.             c=c>>k;
  168.             c&=1;
  169.             b|=c;
  170.             b<<=1;
  171.             }
  172.         b>>=1;
  173.  
  174. /* this is for HAM pictures */
  175.         if (mhd.npl==6) {
  176.             c=(b&48)>>4;
  177.             b&=15;
  178.             if (c==0) {
  179.                 b*=3;
  180.                 lr=cmap[b]; lb=cmap[b+1]; lg=cmap[b+2];
  181.                 }
  182.             if (c==1) lb=b;
  183.             if (c==2) lr=b;
  184.             if (c==3) lg=b;
  185.             }
  186.         if (mhd.npl!=6) {
  187.             b&=31;
  188.             b*=3;
  189.             lr=cmap[b]; lb=cmap[b+1]; lg=cmap[b+2];
  190.             }
  191.         m=lr+lb+lg; m=m/3;
  192.         if (m<0) m=0;
  193.         if (m>14) m=14;
  194.         putc(hex[m],fout);
  195.         }
  196.     }
  197. }
  198. fprintf(fout,"\r");
  199. /* Hold the 'showpage' if there is an appended character */
  200. if (!(fl&1)) fprintf(fout,"showpage\r");
  201. fclose(fout);
  202. printf("Done !!!\n");
  203. free(misc);
  204. free(raster);
  205. }
  206.